/*  1:   */ package org.jetbrains.jps.model.serialization;
/*  2:   */ 
/*  3:   */

import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtilRt;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.jps.TimingLog;
import org.jetbrains.jps.model.JpsElement;

import java.io.File;
import java.io.IOException;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */
/* 13:   */ 
/* 14:   */ public abstract class JpsLoaderBase
/* 15:   */ {
/* 16:   */   private final JpsMacroExpander a;
/* 17:   */   
/* 18:   */   protected JpsLoaderBase(JpsMacroExpander paramJpsMacroExpander)
/* 19:   */   {
/* 20:36 */     this.a = paramJpsMacroExpander;
/* 21:   */   }
/* 22:   */   
/* 23:   */   protected Element loadRootElement(File paramFile)
/* 24:   */   {
/* 25:40 */     return loadRootElement(paramFile, this.a);
/* 26:   */   }
/* 27:   */   
/* 28:   */   protected <E extends JpsElement> void loadComponents(File paramFile, String paramString, JpsElementExtensionSerializerBase<E> paramJpsElementExtensionSerializerBase, E paramE)
/* 29:   */   {
/* 30:47 */     String str = paramJpsElementExtensionSerializerBase.getConfigFileName();
/* 31:48 */     File localFile = new File(paramFile, str != null ? str : paramString);
/* 32:49 */     Runnable localRunnable = TimingLog.startActivity("loading: " + localFile.getName() + ":" + paramJpsElementExtensionSerializerBase.getComponentName());
/* 33:   */     Element localElement;
/* 34:51 */     if (localFile.exists()) {
/* 35:52 */       localElement = JDomSerializationUtil.findComponent(loadRootElement(localFile), paramJpsElementExtensionSerializerBase.getComponentName());
/* 36:   */     } else {
/* 37:55 */       localElement = null;
/* 38:   */     }
/* 39:58 */     if (localElement != null) {
/* 40:59 */       paramJpsElementExtensionSerializerBase.loadExtension(paramE, localElement);
/* 41:   */     } else {
/* 42:62 */       paramJpsElementExtensionSerializerBase.loadExtensionWithDefaultSettings(paramE);
/* 43:   */     }
/* 44:64 */     localRunnable.run();
/* 45:   */   }
/* 46:   */   
/* 47:   */   protected static Element loadRootElement(File paramFile, JpsMacroExpander paramJpsMacroExpander)
/* 48:   */   {
/* 49:   */     try
/* 50:   */     {
/* 51:69 */       Element localElement = JDOMUtil.loadDocument(paramFile).getRootElement();
/* 52:70 */       paramJpsMacroExpander.substitute(localElement, SystemInfo.isFileSystemCaseSensitive);
/* 53:71 */       return localElement;
/* 54:   */     }
/* 55:   */     catch (JDOMException localJDOMException)
/* 56:   */     {
/* 57:74 */       throw new RuntimeException("Cannot parse xml file " + paramFile.getAbsolutePath() + ": " + localJDOMException.getMessage(), localJDOMException);
/* 58:   */     }
/* 59:   */     catch (IOException localIOException)
/* 60:   */     {
/* 61:77 */       throw new RuntimeException("Cannot read file " + paramFile.getAbsolutePath() + ": " + localIOException.getMessage(), localIOException);
/* 62:   */     }
/* 63:   */   }
/* 64:   */   
/* 65:   */   protected static boolean isXmlFile(File paramFile)
/* 66:   */   {
/* 67:82 */     return (paramFile.isFile()) && (FileUtilRt.extensionEquals(paramFile.getName(), "xml"));
/* 68:   */   }
/* 69:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.serialization.JpsLoaderBase

 * JD-Core Version:    0.7.0.1

 */